<?php
$sendStr = '00 00 00 00 00 06 01 03 00 00 00 02';  // 16进制数据
$sendStrArray = str_split(str_replace(' ', '', $sendStr), 2);  // 将16进制数据转换成两个一组的数组
$socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname("tcp"));  // 创建Socket
echo "正在连接：\n";
if (socket_connect($socket, "192.168.8.124", 8000)) {  //连接
    echo "111\n";
    for ($j = 0; $j < count($sendStrArray); $j++) {
     
        socket_write($socket, chr(hexdec($sendStrArray[$j])));  // 逐组数据发送
    }
     
    //向打开的套集字写入数据（发送数据）
    //$st="socket send message";
    //$length = strlen($st);
    //$s = socket_write($socket, $st, $length);
    //从套接字中获取服务器发送来的数据
    //$msg = socket_read($socket,8190);
    //echo $msg;
    $receiveStr = "";
    $receiveStr = socket_read($socket, 1024, PHP_BINARY_READ);  // 采用2进制方式接收数据
    $receiveStrHex = bin2hex($receiveStr);  // 将2进制数据转换成16进制
    echo "client:" . $receiveStrHex;
}
socket_close($socket);  // 关闭Socket
?>